<?php

include_once('dao.connection.php');
include_once('entity.point.php');

class PointDAO{
    
    private static $instance;
    
    public static function getInstance() {
        if (!isset(self::$instance))
            self::$instance = new PointDAO();
            
        return self::$instance;
    }
    
    private function __construct() {
       $this->connection = Connection::getInstance();
    }    
   
    public function findById($id) {

        $sql = 'SELECT id_point, nm_point, x(point_geom), y(point_geom)
            FROM point
            WHERE id_point='.$id;
        $result = $this->connection->executeSQL($sql);
        
        while (list($id, $name, $polygon) = pg_fetch_row($result)) {
            $point = new Point();
            $point->setId($id);
            $point->setX($x);
            $point->setY($y);
        }
        return $point;
    }
    
   
    public function listPoints() {

        $sql = 'SELECT id_point,nm_point,x(point_geom),y(point_geom) FROM point';
        $result = $this->connection->executeSQL($sql);
        
        while (list($id,$name,$x,$y) = pg_fetch_row($result)) {            
            $point = new Point();
            $point->setId($id);
            $point->setName($name);
            $point->setX($x);
            $point->setY($y);
          
            $points[] = $polygon;
        }
        return $points;
    }


    
    
}


?>
